package com.orphan.supplier.mq;

import com.orphan.supplier.po.Suppliergoods;
import com.orphan.supplier.po.Supplierorder;
import com.orphan.supplier.service.ISuppliergoodsService;
import com.orphan.supplier.service.ISupplierorderService;
import com.orphan.util.dto.SettlementSupplierDto;
import com.orphan.util.mqConfig.MQUtil;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 获取审核系统发过来的供货订单
 */
@Component
@RabbitListener(queues = {"queue1"})
public class SupplierMq {
    @Resource
    ISupplierorderService supplierorderService;
    @Resource
    ISuppliergoodsService suppliergoodsService;
    @Resource
    private MQUtil mqUtil;
    @RabbitHandler
    public void receive(SettlementSupplierDto dto, Message message, Channel channel){
        System.out.println(dto);
        Supplierorder supplierorder=new Supplierorder();
        supplierorder.setTPlanid(dto.getPlanId());
        supplierorder.setTSuppliername(dto.getSupplierName());
        supplierorder.setTTotalMoney(dto.getTotalMoney());
        Suppliergoods suppliergoods=new Suppliergoods();
        suppliergoods.setTGoodsname(dto.getSupplierGoods().get(0).getGoodsName());
        suppliergoods.setTGoodstype(dto.getSupplierGoods().get(0).getType());
        suppliergoods.setTPrice(dto.getSupplierGoods().get(0).getPrice());
        suppliergoods.setTGoodsnum(dto.getSupplierGoods().get(0).getGoodsNum());
        suppliergoods.setTSize(dto.getSupplierGoods().get(0).getSize());
        suppliergoods.setTFkId(dto.getSupplierGoods().get(0).getTFkId());
        supplierorderService.addOrder(supplierorder);
        suppliergoodsService.addgoods(suppliergoods);
        mqUtil.ack(message,channel);
    }
}
